package com.beordie.service.impl;

import com.beordie.dao.ICarDao;
import com.beordie.dao.impl.CarDaoImpl;
import com.beordie.model.Car;
import com.beordie.model.FormatCar;
import com.beordie.service.ICarService;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname CarServiceImpl
 * @Description car 表的服务层
 * @Date 2021/7/11 21:20
 * @Created 30500
 */
public class CarServiceImpl implements ICarService {
    ICarDao carDao = new CarDaoImpl();

    @Override
    public List<FormatCar> getAllCars() {
        List<FormatCar> formatCars = new ArrayList<>();
        List<Car> cars = carDao.getAllCars();
        if (cars != null && cars.size() > 0)
            for (Car car : cars)
                formatCars.add(new FormatCar(car));
        return formatCars;
    }

    @Override
    public FormatCar getCarByNumber(String number) {
        Car car = carDao.getCarByNumber(number);
        return new FormatCar(car);
    }

    @Override
    public int insert(Car car) {
        return carDao.insert(car);
    }

    @Override
    public int updateById(Car car) {
        return carDao.updateById(car);
    }

    @Override
    public int deleteById(int id) {
        return carDao.deleteById(id);
    }

    @Override
    public List<FormatCar> getCarsByLimit(boolean isLimit, int start, int size) {
        List<FormatCar> formatCars = new ArrayList<>();
        List<Car> cars = carDao.getCarsByLimit(isLimit, start, size);
        if (cars != null && cars.size() > 0)
            for (Car car : cars)
                formatCars.add(new FormatCar(car));
        return formatCars;
    }

    @Override
    public int getCount() {
        return carDao.getCount();
    }
}
